﻿using SqlSugar;

namespace NetMicro.Domains
{
    /// <summary>
    /// 包含指定类型主键的实体
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    public class Entity<TKey> : IEntity, IDeleted, IVersion
    {
        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = false)]

        public virtual TKey Id { get; set; }

        /// <summary>
        /// 逻辑删除.0为正常，1为已删除
        /// </summary>

        public bool IsDeleted { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>

        public long Version { get; set; } = 1;

        /// <summary>
        /// 初始化
        /// </summary>
        public virtual void Init() { }

        /// <summary>
        /// 修改初始化
        /// </summary>
        /// <param name="entityBase"></param>
        public virtual void UpdateInit<TEntity>(TEntity entityBase) where TEntity : Entity<TKey> { }


        /// <summary>
        /// 假删除初始化
        /// </summary>
        /// <param name="entityBase"></param>
        public virtual void SoftDeleteInit<TEntity>(TEntity entityBase) where TEntity : Entity<TKey> { }
    }

    /// <summary>
    /// 主键类型为long的实体
    /// </summary>
    public abstract class Entity : Entity<long>
    {

    }
}
